package com.kitty.game.pet.handler.upgrade;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.config.Skill;
import com.kitty.game.equip.message.RespNotifyMiscEx;
import com.kitty.game.equip.model.RoleEquip;
import com.kitty.game.pet.PetDataPool;
import com.kitty.game.pet.message.RespForgetPetSkill;
import com.kitty.game.pet.model.Pet;
import com.kitty.game.role.model.Role;
import com.kitty.game.role.service.RoleService;
import com.kitty.game.skill.SkillDataPool;
import com.kitty.mina.message.MessagePusher;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**宠物顿悟*/
@Component
public class PetInsightHandler extends UpgradePetHandler {


    @Override
    public String acceptUpgradePet(Role role, Pet pet, String ids, String itemPos, String costType, String otherPetPos) {
        logger.error("宠物顿悟{},物品id{},物品位置{},{},{}",pet.getName(),ids,itemPos,costType,otherPetPos);
        RoleEquip roleEquip = equipService.getRoleEquipByPos(role, Short.parseShort(itemPos));
        if (roleEquip == null) {
            return ERROR_ITEM;
        }
        if (!roleEquip.getName().equals("宠物顿悟丹")){
            return ERROR_ITEM;
        }
        equipService.delEquipNum(role, roleEquip, 1);
        int index = new Random().nextInt(10);
        if (index >=8){
            return "顿悟失败！";
        }
        // 随机出技能
        List<String> list = PetDataPool.dunwuSkill;
        ArrayList<String> arrayList = new ArrayList(list);

        switch(pet.getPolar()){
            case 1:
                arrayList.add("天生神力");
                break;
            case 2:
                arrayList.add("拔苗助长");
                break;
            case 3:
                arrayList.add("防微杜渐");
                break;
            case 4:
                arrayList.add("十万火急");
                break;
            case 5:
                arrayList.add("鞭长莫及");
                break;
        }
        int i = new Random().nextInt(arrayList.size());
        String name = arrayList.get(i);
        Skill skill = SkillDataPool.name2Skill.get(name);
        logger.error("没有技能=={}",name);
        RespForgetPetSkill respForgetPetSkill = new RespForgetPetSkill();
        SpringUtils.getPetService().dunwuPetSkill(role, pet, (short) skill.getSkillId(), (short)1,respForgetPetSkill);
        MessagePusher.pushMessage(role,new RespNotifyMiscEx("顿悟成功"));
        SpringUtils.getBean(RoleService.class).addAchieveScore(role,"201018");
        SpringUtils.getBean(RoleService.class).addAchieveScore(role,"201012");

        respForgetPetSkill.setMonsterId(pet.getId());
        respForgetPetSkill.setSkillId((short) skill.getSkillId());
        respForgetPetSkill.setFlag((byte) 1);
        MessagePusher.pushMessage(role,respForgetPetSkill);
        return null;
    }
}
